package org.gl.utils;



import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.os.Bundle;

public class SignUtil extends Activity {
    
    private static char[] toChars(byte[] mSignature) {
        byte[] sig = mSignature;
        final int N = sig.length;
        final int N2 = N*2;
        char[] text = new char[N2];

        for (int j=0; j<N; j++) {
          byte v = sig[j];
          int d = (v>>4)&0xf;
          text[j*2] = (char)(d >= 10 ? ('a' + d - 10) : ('0' + d));
          d = v&0xf;
          text[j*2+1] = (char)(d >= 10 ? ('a' + d - 10) : ('0' + d));
        }

        return text;
        }
    

    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        try {
//            //01-30 21:11:07.507: I/System.out(23733): 177496438 / 0xa946176
//            //01-30 21:39:36.702: I/System.out(26332): 3082023f308201a8a00302010202044c984ccc300d06092a864886f70d01010505003064310b300906035504061302434e3110300e060355040813074a69616e6773753110300e060355040713074e616e6a696e6731153013060355040a130c456d6167736f667477617265310d300b060355040b13045469616e310b3009060355040313024c75301e170d3130303932313036313232385a170d3338303230363036313232385a3064310b300906035504061302434e3110300e060355040813074a69616e6773753110300e060355040713074e616e6a696e6731153013060355040a130c456d6167736f667477617265310d300b060355040b13045469616e310b3009060355040313024c7530819f300d06092a864886f70d010101050003818d0030818902818100835c192e7385ff63ab7bc8469df0224caac1eeea054e6a9bca9d7f3915db090b2bc3cde0f587da732fe45ce55dba30fe3cda5dfbb9797d7b05d59794916d61d5678b3a40722eb09ede89f1e4135a289a8a8464de19d6aab2f2bd8a702e6f53107ef51f25985bdca1a8572eed13827aaf96f8fcfaefe00d31881058134964fd970203010001300d06092a864886f70d01010505000381810072881563e0b07637bf03a6862e3dd9e7dd7186a3355639937748a686119ad59a612a95c6eb8b87b05d0353fc69eefe1b195eafaa08c08f1bf4d20659821ed67fd93d387912af03589d42551affbb6bdfdf81c4e702b32df611a9fcc8ad309edc02d694c948690258245e429bfd0049fd65e284c35d86e046a8abb0a4ee218eff
            PackageInfo pis = this.getPackageManager().getPackageInfo("com.xx.xx", PackageManager.GET_SIGNATURES);
            Signature[] sigs = pis.signatures;
            
            System.out.println("version code=" + pis.versionCode);
            System.out.println(sigs[0].hashCode()+ " / 0x" + Integer.toHexString(sigs[0].hashCode()));
            String sig = new String(sigs[0].toChars());
            System.out.println("to Char "+sig.length()+" length: " + sig);
            
            String apk = "/sdcard/xx.apk";
            PackageInfo pi = this.getPackageManager().getPackageArchiveInfo(apk, PackageManager.GET_SIGNATURES);
            
            String main = new String(pi.signatures[0].toChars());
            System.out.println("to Char "+main.length()+" apk:" + main);
            System.out.println(main.equals(sig));
        } catch (NameNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        

    }
    
 
}